﻿using eGrid_App;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Windows;
using System.Windows.Markup;
using System.Windows.Controls;

namespace GISforTT_Test
{
    
    
    /// <summary>
    ///This is a test class for BookmarkListFrameTest and is intended
    ///to contain all BookmarkListFrameTest Unit Tests
    ///</summary>
    [TestClass()]
    public class BookmarkListFrameTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        [ClassInitialize()]
        public static void MyClassInitialize(TestContext testContext)
        {
            TouchToolkit.Framework.GestureFramework.Initialize(new TouchToolkit.Framework.TouchInputProviders.Windows7TouchInputProvider(), new Canvas(), System.Reflection.Assembly.GetExecutingAssembly());
        }
        
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for BookmarkListFrame Constructor
        ///</summary>
        [TestMethod()]
        public void BookmarkListFrameConstructorTest()
        {
            ScatterLayer tpScatterView = new ScatterLayer(new TouchToolkit.Framework.TouchInputProviders.Windows7TouchInputProvider(), 500, 500);
            Point pt = new Point(200, 200);
            double orientation = 180.00;
            BookmarkListFrame target = new BookmarkListFrame(tpScatterView, pt, orientation);
            Assert.AreEqual(pt, target.Center);
            Assert.AreEqual(orientation, target.Orientation);
        }

        /// <summary>
        ///A test for AddBookmark
        ///</summary>
        [TestMethod()]
        public void AddBookmarkTest()
        {
            ScatterLayer tpScatterView = new ScatterLayer(new TouchToolkit.Framework.TouchInputProviders.Windows7TouchInputProvider(), 500, 500);
            Point pt = new Point(200, 200);
            double orientation = 180.00;
            BookmarkListFrame target = new BookmarkListFrame(tpScatterView, pt, orientation);
            Bookmark bookmark = new Bookmark(new ESRI.ArcGIS.Client.Geometry.Envelope(), "Test Description", "123", Bookmark.BookmarkPriority.High);
            BookmarkListItem expected = new BookmarkListItem(bookmark);
            BookmarkListItem actual;
            actual = target.AddBookmark(bookmark);
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for OutOfBounds
        ///</summary>
        [TestMethod()]
        [DeploymentItem("eGrid_App.exe")]
        public void OutOfBoundsTest()
        {
            ScatterLayer tpScatterView = new ScatterLayer(new TouchToolkit.Framework.TouchInputProviders.Windows7TouchInputProvider(), 500, 500);
            Point pt = new Point(200, 200);
            double orientation = 180.00;
            BookmarkListFrame_Accessor target = new BookmarkListFrame_Accessor(tpScatterView, pt, orientation);
            Point inPt = new Point(200, 300);
            bool expected = false;
            bool actual;
            actual = target.OutOfBounds(inPt);
            Assert.AreEqual(expected, actual);
            Point outPt = new Point(1000, 200);
            
            actual = target.OutOfBounds(outPt);
            //this should be out of bounds
            Assert.AreEqual(true, actual);
        }

        /// <summary>
        ///A test for RemoveBookmarkItem
        ///</summary>
        [TestMethod()]
        public void RemoveBookmarkItemTest()
        {
            ScatterLayer tpScatterView = new ScatterLayer(new TouchToolkit.Framework.TouchInputProviders.Windows7TouchInputProvider(), 500, 500);
            Point pt = new Point(200, 200);
            double orientation = 180.00;
            BookmarkListFrame_Accessor target = new BookmarkListFrame_Accessor(tpScatterView, pt, orientation);
            Bookmark bm1 = new Bookmark(new ESRI.ArcGIS.Client.Geometry.Envelope(), "Test Description", "123", Bookmark.BookmarkPriority.High);
            Bookmark bm2 = new Bookmark(new ESRI.ArcGIS.Client.Geometry.Envelope(), "Bookmark 2", "321", Bookmark.BookmarkPriority.Low);
            BookmarkListItem item1 = new BookmarkListItem(bm1);
            BookmarkListItem item2 = new BookmarkListItem(bm2);
            target.BookmarkListItems.Clear();
            target.BookmarkListBox.Items.Add(item1);
            target.BookmarkListBox.Items.Add(item2);
            //We should have 2 items in our list box now
            Assert.AreEqual(2, target.BookmarkListBox.Items.Count);
            target.RemoveBookmarkItem(item2);
            //we should have 1 item now
            Assert.AreEqual(1, target.BookmarkListBox.Items.Count);
            //the deleted item shouldn't be in the list
            Assert.AreEqual(false, target.BookmarkListItems.Contains(item2));
            //the non-deleted item should still be in the list
            Assert.AreEqual(true, target.BookmarkListItems.Contains(item1));

            target.RemoveBookmarkItem(item2);
            //trying to remove something not in the list should not do anything
            Assert.AreEqual(1, target.BookmarkListItems.Count);//we should still have 1 item in our list
        }

        /// <summary>
        ///A test for BookmarkListItems
        ///</summary>
        [TestMethod()]
        public void BookmarkListItemsTest()
        {
            ScatterLayer tpScatterView = new ScatterLayer(new TouchToolkit.Framework.TouchInputProviders.Windows7TouchInputProvider(), 500, 500);
            Point pt = new Point(200, 200);
            double orientation = 180.00;
            BookmarkListFrame_Accessor target = new BookmarkListFrame_Accessor(tpScatterView, pt, orientation);
            Bookmark bm1 = new Bookmark(new ESRI.ArcGIS.Client.Geometry.Envelope(), "Test Description", "123", Bookmark.BookmarkPriority.High);
            Bookmark bm2 = new Bookmark(new ESRI.ArcGIS.Client.Geometry.Envelope(), "Bookmark 2", "321", Bookmark.BookmarkPriority.Low);
            BookmarkListItem item1 = new BookmarkListItem(bm1);
            BookmarkListItem item2 = new BookmarkListItem(bm2);
            target.BookmarkListItems.Clear();
            target.BookmarkListBox.Items.Add(item1);
            target.BookmarkListBox.Items.Add(item2);

            ItemCollection actual;
            actual = target.BookmarkListItems;
            //we should have 2 items
            Assert.AreEqual(2, actual.Count);
            //we should the the correct items
            Assert.AreEqual(item1, actual.GetItemAt(0));
            Assert.AreEqual(item2, actual.GetItemAt(1));
        }
    }
}
